package net.hn.hnms.biz.support.controller;

import io.swagger.annotations.*;
import net.hn.hnms.biz.support.domain.dto.ResistanceCurveDto;
import net.hn.hnms.biz.support.domain.dto.SupportCloudDto;
import net.hn.hnms.biz.support.domain.vo.*;
import net.hn.hnms.biz.support.service.RoofService;
import net.hn.hnms.biz.support.service.SupportService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;


/**
 * 功能描述: 顶板检测
 *
 * @auther: WangLong
 * @date: 2022/8/9 14:10
 * @return
 */

@Api(value = "灾害监测-顶板检测", tags = {"灾害监测-顶板检测"})
@RestController
@RequestMapping("roof")
public class RoofController {
    /**
     * 支架服务
     */
    @Resource
    private SupportService supportService;

    @Resource
    private RoofService roofService;


    @ApiOperation("统计信息")
    @GetMapping("holder/statisticalInformation")
    @AutoSetMineCode
    public R<List<StatisticalInformationMapVo>> holderStatisticalInformation(@ApiParam(value = "煤矿编码") String mineCode) {

        StatisticalInformationVo statisticalInformationVo = supportService.statisticalInformation(mineCode);
        List<StatisticalInformationMapVo> list = new ArrayList<>();
        StatisticalInformationMapVo maxHolderResistanceVo = new StatisticalInformationMapVo();
        maxHolderResistanceVo.setLable("最大支架阻力");
        maxHolderResistanceVo.setValue(statisticalInformationVo.getMaxHolderResistance());
        maxHolderResistanceVo.setUnint("MPa");
        list.add(maxHolderResistanceVo);
        StatisticalInformationMapVo maxHolderLocationVo = new StatisticalInformationMapVo();
        maxHolderLocationVo.setLable("最大阻力位置");
        maxHolderLocationVo.setValue(BigDecimal.valueOf(statisticalInformationVo.getMaxHolderLocation()));
        maxHolderLocationVo.setUnint("立柱");
        list.add(maxHolderLocationVo);
        StatisticalInformationMapVo onLinePoint = new StatisticalInformationMapVo();
        onLinePoint.setLable("在线测点数");
        onLinePoint.setValue(BigDecimal.valueOf(statisticalInformationVo.getOnLinePoint()));
        onLinePoint.setUnint("个");
        list.add(onLinePoint);
        StatisticalInformationMapVo policePointVo = new StatisticalInformationMapVo();
        policePointVo.setLable("报警测点数");
        policePointVo.setValue(BigDecimal.valueOf(statisticalInformationVo.getPolicePoint()));
        policePointVo.setUnint("个");
        list.add(policePointVo);

        return R.ok(list);
    }

    @ApiOperation("支架阻力位移检测/支架检测/支架位移曲线")
    @GetMapping("holder/move")
    @AutoSetMineCode
    public R<List<HolderResistanceMoveVo>> holderMove(@ApiParam(value = "煤矿编码") String mineCode) {
        List<HolderResistanceMoveVo> list = supportService.selectNowList(mineCode);
        return R.ok(list);

    }

    @ApiOperation("支架检测/支架位移曲线")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "输入1|2：1-支架压力，2-位移行程", required = true, paramType = "query", dataType = "String")
    })
    @GetMapping("holder/pressure/{id}")
    @AutoSetMineCode
    public R<EchartVo> holderPressure(@PathVariable String id, @ApiParam(value = "煤矿编码") String mineCode) {

        EchartVo list = supportService.holderPressure(id, mineCode);
        return R.ok(list);

    }

    @ApiOperation("最大工作阻力变化曲线")
    @GetMapping("holder/resistanceCurve")
    @AutoSetMineCode
    public R<EchartVo> holderResistanceCurve(ResistanceCurveDto resistanceCurveDto) {
        List<ResistanceCurveVo> list1 = supportService.holderResistanceCurve(resistanceCurveDto);
        List<ResistanceCurveVo> list = list1.stream().sorted(Comparator.comparing(ResistanceCurveVo::getDateTime)).collect(Collectors.toList());

        //echartVo
        EchartVo echartVo = new EchartVo();
        List<Date> dateList = new ArrayList<>();
        List<BigDecimal> bigDecimalList = new ArrayList<>();
        for (ResistanceCurveVo resistanceCurveVo : list) {
            dateList.add(resistanceCurveVo.getDateTime());
            bigDecimalList.add(resistanceCurveVo.getValue());
        }
        echartVo.setDate(dateList);
        echartVo.setValue(bigDecimalList);
        return R.ok(echartVo);

    }

    @ApiOperation("支架压力分析")
    @GetMapping("/holder/analysis")
    @AutoSetMineCode
    public R<HolderAnalyseVo> holderAnalysis(String mineCode) {
        return R.ok(supportService.getHolderAnalysis(mineCode));
    }


    @ApiOperation("支架云图")
    @GetMapping("holder/nephogram")
    @AutoSetMineCode
    public R<List<List<Object>>> holdernNephogram(SupportCloudDto supportCloudDto) {

        List<List<Object>> list = supportService.holdernNephogram(supportCloudDto);

        return R.ok(list);

    }

    @ApiOperation("顶板灾害-基础信息")
    @GetMapping("/basicInfo")
    @AutoSetMineCode
    public R<RoofBaseInfoVo> basicInfo(@ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(roofService.getRoofBaseInfo(mineCode));
    }


}
